package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

//    mapper接口调用数据库
    @Autowired
    private DeptMapper deptMapper;


    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }

    @Override
    public void delete(Integer id) {
        deptMapper.deleteByid(id);
    }

    @Override
    public void add(Dept dept) {
//        补全属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.inster(dept);
    }


    @Override
    public Dept getByid(Integer id) {
        Dept dept = deptMapper.getIByid(id);
        return dept;
    }

    @Override
    public void putdept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.putdept(dept);
    }


}
